home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Programming / MiniGL / include / mgl / context.h < prev    next >
Encoding:
C/C++ Source or Header  |  2000-04-07  |  6.7 KB  |  265 lines

  1. /*
  2.  * $Id: context.h,v 1.1.1.1 2000/04/07 19:44:51 tfrieden Exp $
  3.  *
  4.  * $Date: 2000/04/07 19:44:51 $
  5.  * $Revision: 1.1.1.1 $
  6.  *
  7.  * (C) 1999 by Hyperion
  8.  * All rights reserved
  9.  *
  10.  * This file is part of the MiniGL library project
  11.  * See the file Licence.txt for more details
  12.  *
  13.  */
  14.  
  15. #ifndef __CONTEXT_H
  16. #define __CONTEXT_H
  17.  
  18. #include "mgl/matrix.h"
  19. #include "mgl/config.h"
  20. #include "mgl/vertexbuffer.h"
  21.  
  22. #include <intuition/intuition.h>
  23.  
  24. #ifdef __PPC__
  25. #include <devices/timer.h>
  26.  
  27. typedef struct LockTimeHandle_s
  28. {
  29.     struct timeval StartTime;
  30. } LockTimeHandle;
  31. #else
  32. typedef struct LockTimeHandle_s
  33. {
  34.     ULONG s_hi, s_lo;
  35.     ULONG e_freq;
  36. } LockTimeHandle;
  37. #endif
  38.  
  39. struct GLcontext_t;
  40.  
  41. typedef void (*DrawFn)(struct GLcontext_t *);
  42.  
  43. typedef enum
  44. {
  45.     MGLKEY_F1, MGLKEY_F2, MGLKEY_F3, MGLKEY_F4, MGLKEY_F5, MGLKEY_F6, MGLKEY_F7, MGLKEY_F8,
  46.     MGLKEY_F9, MGLKEY_F10,
  47.     MGLKEY_CUP, MGLKEY_CDOWN, MGLKEY_CLEFT, MGLKEY_CRIGHT
  48. } MGLspecial;
  49.  
  50. typedef void (*KeyHandlerFn)(char key);
  51. typedef void (*SpecialHandlerFn)(MGLspecial special_key);
  52. typedef void (*MouseHandlerFn)(GLint x, GLint y, GLbitfield buttons);
  53. typedef void (*IdleFn)(void);
  54.  
  55. struct GLcontext_t
  56. {
  57.     /*
  58.     ** The primitive with which glBegin was called,
  59.     ** or GL_BASE if outside glBegin/glEnd
  60.     */
  61.  
  62.     GLenum      CurrentPrimitive;
  63.  
  64.     /*
  65.     ** Current error
  66.     */
  67.     GLenum      CurrentError;
  68.  
  69.     /*
  70.     ** The ModelView/Projection matrix stack.
  71.     ** Note that the topmost (= current) matrix is not the
  72.     ** top of the stack, but rather one of the ModelView[]/Projection[] below.
  73.     ** This makes copying the matrices unnecessary...
  74.     */
  75.     Matrix      ModelViewStack[MODELVIEW_STACK_SIZE];
  76.     int         ModelViewStackPointer;
  77.  
  78.     Matrix      ProjectionStack[PROJECTION_STACK_SIZE];
  79.     int         ProjectionStackPointer;
  80.  
  81.     /*
  82.     ** The current ModelView/Projeciton matrix.
  83.     ** The matrix multiplication routine will switch between those
  84.     ** two to avoid copying stuff.
  85.     */
  86.     Matrix      ModelView[2];
  87.     GLuint      ModelViewNr;
  88.  
  89.     #define     CurrentMV (&(context->ModelView[context->ModelViewNr]))
  90.     #define     SwitchMV  context->ModelViewNr = !(context->ModelViewNr)
  91.  
  92.     Matrix      Projection[2];
  93.     GLuint      ProjectionNr;
  94.  
  95.     #define     CurrentP (&(context->Projection[context->ProjectionNr]))
  96.     #define     SwitchP  context->ProjectionNr = !(context->ProjectionNr)
  97.  
  98.     // The current matrix mode (GL_MODELVIEW or GL_PROJECTION)
  99.     GLuint      CurrentMatrixMode;
  100.  
  101.  
  102.     /*
  103.     ** Vertex buffers
  104.     ** A call to glVertex*() will fill one entry of the vertex buffer
  105.     ** with the current data. glEnd() will go over this data and
  106.     ** draw the primitives based on this.
  107.     */
  108.     MGLVertex * VertexBuffer;
  109.     GLuint      VertexBufferSize;           // Size of the buffer
  110.     GLuint      VertexBufferPointer;        // Next free entry
  111.  
  112.     /*
  113.     ** Current colors and normals
  114.     */
  115.     GLuint      ClearColor;
  116.     W3D_Double  ClearDepth;
  117.     MGLColor    CurrentColor;
  118.     MGLNormal   CurrentNormal;
  119.     GLfloat     CurrentTexS, CurrentTexT;
  120.  
  121.     /*
  122.     ** The flag indicates wether the combined matrix is valid or not.
  123.     ** If it indicates GL_TRUE, the CombinedMatrix field contains the
  124.     ** product of the ModelView and Projection matrix.
  125.     */
  126.     GLboolean   CombinedValid;
  127.     Matrix      CombinedMatrix;
  128.  
  129.     /*
  130.     ** Scale factors for the transformation of normalized coordinates
  131.     ** to window coordinates. The *x and *y values are set by glViewPort.
  132.     ** *z is set by glDepthRange, which also sets near and far.
  133.     */
  134.     GLdouble    sx,sy,sz;
  135.     GLdouble    ax,ay,az;
  136.     GLdouble    near,far;
  137.  
  138.     // CullFace mode
  139.     GLenum      CurrentCullFace;
  140.     GLenum      CurrentFrontFace;
  141.  
  142.     // Pixel states
  143.     GLint       PackAlign;
  144.     GLint       UnpackAlign;
  145.  
  146.     /*
  147.     ** GL Rendering States
  148.     */
  149.     GLboolean   AlphaTest_State;
  150.     GLboolean   Blend_State;
  151.     GLboolean   Texture2D_State;
  152.     GLboolean   TextureGenS_State;
  153.     GLboolean   TextureGenT_State;
  154.     GLboolean   Fog_State;
  155.     GLboolean   Scissor_State;
  156.     GLboolean   CullFace_State;
  157.     GLboolean   DepthTest_State;
  158.     GLboolean   PointSmooth_State;
  159.     GLboolean   Dither_State;
  160.     GLboolean   ZOffset_State;
  161.  
  162.     /*
  163.     ** 'Internal' states
  164.     */
  165.  
  166.     GLboolean   FogDirty;
  167.     GLdouble    FogStart;
  168.     GLdouble    FogEnd;
  169.  
  170.     /*
  171.     ** Drawing and clipping functions for the current primitive
  172.     */
  173.  
  174.     DrawFn      CurrentDraw;
  175.  
  176.     /*
  177.     ** Warp3D specific stuff
  178.     */
  179.  
  180.     W3D_Context *           w3dContext;
  181.     struct Window *         w3dWindow;
  182.     struct Screen *         w3dScreen;
  183.     W3D_Texture **          w3dTexBuffer;
  184.     GLubyte **              w3dTexMemory;
  185.     GLint                   TexBufferSize;
  186.     GLint                   CurrentBinding;
  187.     struct ScreenBuffer *   Buffers[3];
  188.     struct BitMap *         w3dBitMap; // If in windowed mode
  189.     struct RastPort *       w3dRastPort; // for windowed ClipBlit mode
  190.     int                     BufNr;
  191.     int                     NumBuffers;
  192.     W3D_Scissor             scissor;
  193.     GLboolean               w3dLocked;
  194. #ifdef AUTOMATIC_LOCKING_ENABLE
  195.     GLenum                  LockMode;
  196.     LockTimeHandle          LockTime;
  197. #endif
  198.     GLboolean               DoSync;
  199.     ULONG                   w3dChipID;
  200.     ULONG                   w3dFormat;
  201.     ULONG                   w3dAlphaFormat;
  202.     GLint                   w3dBytesPerTexel;
  203.  
  204.     GLenum                  TexEnv;
  205.     GLenum                  MinFilter;
  206.     GLenum                  MagFilter;
  207.     GLenum                  WrapS;
  208.     GLenum                  WrapT;
  209.  
  210.     W3D_Fog                 w3dFog;
  211.     ULONG                   w3dFogMode;
  212.     GLfloat                 FogRange;
  213.     GLfloat                 FogMult;
  214.     GLenum                  ShadeModel;
  215.     GLboolean               DepthMask;
  216.  
  217.     GLboolean               NoMipMapping;
  218.     GLboolean               NoFallbackAlpha;
  219.  
  220.     KeyHandlerFn            KeyHandler;
  221.     MouseHandlerFn          MouseHandler;
  222.     SpecialHandlerFn        SpecialHandler;
  223.     IdleFn                  Idle;
  224.     GLboolean               Running;
  225.  
  226.     GLenum              SrcAlpha;
  227.     GLenum              DstAlpha;
  228.     GLboolean               AlphaFellBack;
  229.  
  230.     GLfloat                 InvRot[9];
  231.     GLboolean       InvRotValid;
  232.  
  233.     GLboolean       WOne_Hint;
  234.  
  235.     GLfloat         ZOffset;
  236.  
  237.     void           *PaletteData;
  238.     GLenum          PaletteFormat;
  239.     GLint           PaletteSize;
  240. };
  241.  
  242. /*
  243. ** The CMATRIX macro give the address of the currently
  244. ** active matrix, depending on the matrix mode.
  245. ** The OMATRIX macro gives the address of the secondary matrix
  246. ** The SMATRIX macro switches the active and backup matrix
  247. */
  248. #define CMATRIX(context) context->CurrentMatrixMode == GL_MODELVIEW ?\
  249.     (&(context->ModelView[context->ModelViewNr])):\
  250.     (&(context->Projection[context->ProjectionNr]))
  251.  
  252. #define OMATRIX(context) context->CurrentMatrixMode == GL_MODELVIEW ?\
  253.     (&(context->ModelView[!(context->ModelViewNr)])):\
  254.     (&(context->Projection[!(context->ProjectionNr)]))
  255.  
  256. #define SMATRIX(context) if (context->CurrentMatrixMode == GL_MODELVIEW)\
  257.     context->ModelViewNr = !(context->ModelViewNr);\
  258.    else context->ProjectionNr = !(context->ProjectionNr)
  259.  
  260.  
  261. typedef struct GLcontext_t * GLcontext;
  262.  
  263. #endif
  264.  
  265.